//
//  DetailCellThree.swift
//  CompareBuying
//
//  Created by 唐先才 on 16/2/18.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class DetailCellThree: UITableViewCell {
    
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var nameLab: UILabel!
    @IBOutlet weak var timeLab: UILabel!
    @IBOutlet weak var contentLab: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        iconView.layer.cornerRadius = 20
        iconView.clipsToBounds = true
    }
    
    func configCellWithModel(model: TxcModel) {
        guard let iconPic = model.UserHeadImage, proName = model.NickName, proTime = model.ReviewTime, proComment = model.ReviewContent else {
            print("评论赋值失败")
            return
        }
        iconView.sd_setImageWithURL(NSURL(string: iconPic))
        nameLab.text = proName
        timeLab.text = proTime
        contentLab.text = proComment
    }

    static func detailCellThreeWith(tableView: UITableView, dataArray: NSMutableArray, indexPath: NSIndexPath) -> UITableViewCell {
        if indexPath.row == 0 {
            let cell31 = UITableViewCell(style: .Default, reuseIdentifier: "cell31")
            guard let cell31Lab = cell31.textLabel else {
                return UITableViewCell()
            }
            cell31.accessoryType = .DisclosureIndicator
            cell31Lab.text = "跟帖:"
            cell31Lab.textColor = UIColor.blackColor()
            cell31Lab.font = UIFont.systemFontOfSize(13)
            return cell31
        }
        if dataArray.count > 0 {
            if let model = dataArray[indexPath.row - 1] as? TxcModel  {
                if model.ReviewContent != nil {
                    if let detailCellThree = tableView.dequeueReusableCellWithIdentifier("detailCellThree") as? DetailCellThree {
                        detailCellThree.configCellWithModel(model)
                        return detailCellThree
                    }
                } else {
                    let cell3 = UITableViewCell(style: .Default, reuseIdentifier: "cell3")
                    guard let cell3Lab = cell3.textLabel else {
                        return UITableViewCell()
                    }
                    cell3Lab.text = "暂无评论，快来抢沙发~~"
                    cell3Lab.textColor = UIColor.blackColor()
                    cell3Lab.textAlignment = NSTextAlignment.Center
                    cell3Lab.font = UIFont.systemFontOfSize(15)
                    return cell3
                }
            }
        }
        return UITableViewCell()
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
